using System;
using System.ComponentModel.DataAnnotations;
using InfoTech.VinhSon.Bussiness;

namespace InfoTech.VinhSon.Models
{
    [Serializable]
    public partial class UserEditModel
    {

        #region Constructor

        public UserEditModel()
        {
        }

        public UserEditModel(User value)
        {
            Id = value.Id;
            Username = value.Username;
            Password = value.Password;
            FirstName = value.FirstName;
            LastName = value.LastName;
            Email = value.Email;
        }

        #endregion

        #region Fields

        private System.Int32 _Id;

        private System.String _Username;

        private System.String _Password;

        private System.String _FirstName;

        private System.String _LastName;

        private System.String _Email;

        #endregion

        #region Properties

        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        public System.Int32 Id
        {
            get
            {
                return _Id;
            }
            set
            {
                _Id = value;
            }
        }

        [Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        [StringLength(50, ErrorMessage = "Value must be under 50 characters")]
        public System.String Username
        {
            get
            {
                return _Username;
            }
            set
            {
                _Username = value;
            }
        }

        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        [StringLength(50, ErrorMessage = "Value must be under 50 characters")]
        public System.String Password
        {
            get
            {
                return _Password;
            }
            set
            {
                _Password = value;
            }
        }

        [Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        [StringLength(50, ErrorMessage = "Value must be under 50 characters")]
        public System.String FirstName
        {
            get
            {
                return _FirstName;
            }
            set
            {
                _FirstName = value;
            }
        }

        [Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        [StringLength(50, ErrorMessage = "Value must be under 50 characters")]
        public System.String LastName
        {
            get
            {
                return _LastName;
            }
            set
            {
                _LastName = value;
            }
        }

        [Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        [StringLength(50, ErrorMessage = "Value must be under 50 characters")]
        public System.String Email
        {
            get
            {
                return _Email;
            }
            set
            {
                _Email = value;
            }
        }

        #endregion

        #region Operators

        public void Update(User value)
        {
            // value.Id = Id;
            value.Username = Username;
            if (!string.IsNullOrEmpty(Password))
                value.Password = Password;
            value.FirstName = FirstName;
            value.LastName = LastName;
            value.Email = Email;
            value.LastModified = DateTime.Now;
        }

        public static implicit operator UserEditModel(User obj)
        {
            return new UserEditModel(obj);
        }

        public static implicit operator User(UserEditModel obj)
        {
            User value = new User();
            obj.Update(value);
            return value;
        }

        #endregion

    }
}
